package com.serkol.ams.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.ams.bean.MyPage;
import com.serkol.ams.bean.MyPageOld;
import com.serkol.ams.entity.Navigation;
import com.serkol.ams.mapper.NavigationMapper;
import com.serkol.ams.service.NavigationService;
import com.serkol.annotation.RedisCache;
import com.serkol.handler.MyLambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author pingan
* @description 针对表【navigation】的数据库操作Service实现
* @createDate 2022-10-28 22:51:10
*/
@Service
public class NavigationServiceImpl extends ServiceImpl<NavigationMapper, Navigation>
    implements NavigationService{

    @Override
    public MyPage<Map<String, Object>> findByBackList(int pageSize, int current) {
        MyLambdaQueryWrapper<Navigation> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.picture(Navigation::getImageId).as("image");
        queryWrapper.select(Navigation::getId, Navigation::getImageId, Navigation::getName, Navigation::getPath,  Navigation::getTargetType,Navigation::getAppid);
        queryWrapper.select(Navigation::getNameUg).as("nameUg").select(Navigation::getTargetType).as("targetType");

  
        Page<Map<String, Object>> page=new Page<>(current,pageSize);
        Page<Map<String, Object>> mapPage = this.baseMapper.selectMapsPage(page, queryWrapper);
        return MyPage.parsePage(mapPage);
    }

    @Override
  //  @Cacheable(cacheNames = "Navigation::home", key = "'findByMiniList'")
    @RedisCache(key = "Navigation::home::findByMiniList",isLang = true)
    public List<Map<String, Object>> findByMiniList() {
        MyLambdaQueryWrapper<Navigation> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.picture(Navigation::getImageId).as("image");
        queryWrapper.select(Navigation::getId, Navigation::getImageId,Navigation::getAppid,Navigation::getPath).select(Navigation::getTargetType).as("targetType");
        queryWrapper.langName(Navigation::getName,Navigation::getNameUg).as("name");

        List<Map<String, Object>> maps = this.listMaps(queryWrapper);
        return maps;
    }

    @Override
    public boolean byDelete(long id) {
        if(id>0) {
            return this.removeById(id);
        }
        return false;
    }
}




